home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / redakcyjne / programy / Weather Watcher Live 6.1.23 / WWL6123.exe / {app} / HTML / CitySearch.ww
Text File  |  2008-08-03  |  5KB  |  140 lines

  1. <html xmlns="http://www.w3.org/1999/xhtml">
  2.   <head>
  3.     <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
  4.     <script src="http://maps.google.com/maps?file=api&v=2&key=ABQIAAAAWBxHsWkYu9yBertEIMndPBQK84YzabrmjY1XhCgn1E5HpVj9IxS1br5Yr2ddJoJNXEp9pVQ_-dU2ZQ" type="text/javascript"></script>
  5.     <script type="text/javascript">
  6.         //***********************
  7.         //*  Declare variables  *
  8.         //***********************
  9.         var xmlURL = 'CitySearchResults.xml';
  10.         var map = null;
  11.         var geocoder = null;
  12.         var selectedStation = null;
  13.         
  14.         var markerArray = [];
  15.         var markerTypeArray = [];
  16.         var markerLatArray = [];
  17.         var markerLongArray = [];
  18.         
  19.         var lastMarker;
  20.         var lastMarkerType;
  21.         
  22.         //**********************************
  23.         //*  Create icons for map markers  *
  24.         //**********************************
  25.         var iconGreen = new GIcon();
  26.         iconGreen.image = "Images/mm_20_green.png";
  27.         iconGreen.iconSize = new GSize(12, 20);
  28.         iconGreen.iconAnchor = new GPoint(6, 20);
  29.     
  30.         var iconBlue = new GIcon();
  31.         iconBlue.image = "Images/mm_20_blue.png";
  32.         iconBlue.iconSize = new GSize(12, 20);
  33.         iconBlue.iconAnchor = new GPoint(6, 20);
  34.         
  35.         function load() 
  36.         {    //****************************            
  37.             //*  Add markers to the map  *
  38.             //****************************            
  39.             var xml = GXml.parse("[XML]");  
  40.             var markers = xml.documentElement.getElementsByTagName("aws:station");  
  41.                 
  42.             //********************
  43.             //*  Create the map  *
  44.             //********************
  45.             map = new GMap2(document.getElementById("map"));
  46.                 map.addControl(new GSmallMapControl());
  47.             map.addControl(new GMapTypeControl());
  48.             map.setCenter(new GLatLng(markers[0].getAttribute("latitude"), markers[0].getAttribute("longitude")), 10);
  49.             geocoder = new GClientGeocoder();
  50.             
  51.             //***************************************
  52.             //*  Add markers found in returned XML  *
  53.             //***************************************
  54.             for (var i = 0; i < markers.length; i++) 
  55.             {    var lat = parseFloat(markers[i].getAttribute("latitude"));
  56.                 var long = parseFloat(markers[i].getAttribute("longitude"));
  57.                 
  58.             
  59.                 var point = new GLatLng(parseFloat(markers[i].getAttribute("latitude")), parseFloat(markers[i].getAttribute("longitude")));    
  60.                 var marker = createMarker(point, markers[i].getAttribute("name"), markers[i].getAttribute("city"), markers[i].getAttribute("state"), markers[i].getAttribute("country"), markers[i].getAttribute("station-type"), markers[i].getAttribute("id"), i + 1, lat, long);
  61.                 map.addOverlay(marker);
  62.                 
  63.                 markerArray[i] = marker;
  64.                 markerTypeArray[i] = markers[i].getAttribute("station-type")
  65.                 markerLatArray[i] = markers[i].getAttribute("latitude")
  66.                 markerLongArray[i] = markers[i].getAttribute("longitude")
  67.             }
  68.         }
  69.         
  70.         function createMarker(point, stationName, stationCity, stationState, stationCountry, stationType, stationID, markerCount, lat, long) 
  71.         {    //************************************************************
  72.             //*  Set the marker color based on the weather station type  *
  73.             //************************************************************
  74.             if (stationState == null) stationState = "";
  75.             if (stationCountry == null) stationCountry = "";
  76.             
  77.             switch (stationType) 
  78.             {     case 'NWS': var marker = new GMarker(point, { title: stationName + "\n" + stationCity + ", " + stationState + stationCountry, icon: iconBlue}); break;
  79.                  default: var marker = new GMarker(point, { title: stationName + "\n" + stationCity + ", " + stationState + stationCountry, icon: iconGreen}); break;
  80.             }    
  81.             
  82.             //******************************
  83.               //*  Add a marker click event  *
  84.             //******************************
  85.               GEvent.addListener(marker, 'click', function() {
  86.                 document.getElementById('WWSelectedCity').innerHTML = stationID;
  87.                 resetLastMarkerImage();
  88.                 marker.setImage('Images/mm_20_red.png');
  89.                 if (stationType == null) stationType = "WeatherBug";
  90.                 lastMarkerType = stationType;
  91.                 lastMarker = marker;
  92.                 map.panTo(new GLatLng(lat, long));
  93.             });
  94.  
  95.               return marker;
  96.         }
  97.         
  98.         function setMapCenter(stationLatitude, stationLongitude)
  99.         {    map.panTo(new GLatLng(stationLatitude, stationLongitude));
  100.         
  101.             resetLastMarkerImage();
  102.  
  103.             for (var i = 0; i < markerArray.length; i++)
  104.             {    if (markerLatArray[i] == stationLatitude)
  105.                 {    if (markerLongArray[i] == stationLongitude)
  106.                     {    lastMarkerType = markerTypeArray[i];
  107.                         if (lastMarkerType == null) lastMarkerType = "WeatherBug";
  108.                         lastMarker = markerArray[i];
  109.                     }
  110.                 }
  111.             
  112.             }
  113.             
  114.             
  115.             lastMarker.setImage('Images/mm_20_red.png');
  116.         }
  117.         
  118.         function resetLastMarkerImage()
  119.         {    if (lastMarkerType != null)
  120.             {    if (lastMarkerType.length > 0)
  121.                 {    if (lastMarkerType == "NWS")
  122.                     {    lastMarker.setImage('Images/mm_20_blue.png');
  123.                     }
  124.                     else
  125.                     {    lastMarker.setImage('Images/mm_20_green.png');
  126.                     }
  127.                 }
  128.             }
  129.         }
  130.         
  131.         function ignoreErrors() 
  132.         {    return true; }
  133.         
  134.         window.onerror = ignoreErrors;
  135.     </script>
  136.   </head>
  137.   <body onload="load()" onunload="GUnload()" STYLE="padding: 0px; margin: 0px; overflow: hidden;">
  138.     <div id="map" style="width: 100%; height: 100%;"></div><DIV ID="WWSelectedCity" STYLE="display:none;"></DIV><DIV ID="ResetCenter" STYLE="display:none;"></DIV>
  139.   </body>
  140. </html>